<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceDeleteEvent extends core {

    public function process() {
        $event_id = intval($_POST['event_id']);
        $user_id = intval($_POST['user_id']);
        $event_id = $this->db->escape($event_id);
        $data = $this->db->get_row("SELECT * FROM events WHERE `event_id`='$event_id' AND `user_id`='$user_id'");
        if ($data) {         
            $query = "DELETE FROM events WHERE `event_id`= '$event_id' AND `user_id`='$user_id'";

            if ($this->db->query($query)===false) {

                $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again'));
            } else {
                $query_delete_guest_in_guestevent = "DELETE FROM guest_event WHERE `event_id`= '$event_id' ";            
                $result = $this->db->query($query_delete_guest_in_guestevent);
                $this->_JSONResponse(array('error' => 0, 'msg' => 'Event has been deleted'));
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Event does not exist'));
        }
    }

}

$processor = new webServiceDeleteEvent();
$processor->process();
?>